$(() => {
	// console.log($('.panel-body button:submit'))
	$('.panel-body button:submit').on('click', e => {
		// 阻止默认事件
		e.preventDefault()
		// 获取用户名和密码
		const data = {
			username: $('#username').val().trim()
			password: $('#password').val().trim()
		}
		// 发送请求
		$.ajax({
			type: "post",
			url: `/admin/user/login`,
			data: data,
			success: res => {
				console.log(res)
				if (res.code !== 200) {
					/* layui.use('layer', () => {
						const layer = layui.layer
						layer.msg('用户名或密码错误')
					}) */
					layer.msg(res.msg, {
						icon: 2,
						time: 1500
					})
					// alert('用户名或密码错误')
					return
				}
				if (res.code === 200) {
					localStorage.setItem('token', res.token)
					layer.msg(res.msg, {
						icon: 1,
						time: 1500
					}, () => {
						$('#username').val('')
						$('#password').val('')
						location.href = 'index.html'
					})
				}
			}
		})
	})

})
